from langchain_community.agent_toolkits.load_tools import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain_experimental.tools import PythonREPLTool
from langchain_experimental.utilities import PythonREPL
from langchain_openai import AzureChatOpenAI
from tool import get_azure_endpoint,get_api_key,get_api_version
from langchain_experimental.agents.agent_toolkits import create_python_agent

if __name__ == '__main__':
    # 参数temperature设置为0.0，从而减少生成答案的随机性。
    llm = AzureChatOpenAI(
        azure_endpoint=get_azure_endpoint().rstrip('/'),  # 移除尾部斜杠，只保留基础URL
        azure_deployment="gpt-4o",  # 重命名为 azure_deployment
        model_name="gpt-4o",
        openai_api_version=get_api_version(),  # 参数名不变
        openai_api_key=get_api_key(),
        openai_api_type="azure",
        temperature=0.0,
    )

    agent = create_python_agent(
        llm,  # 使用前面一节已经加载的大语言模型
        tool=PythonREPLTool(), #使用Python交互式环境工具 REPLTool
        verbose=True #输出中间步骤
    )

    customer_list = ["小明","小黄","小红","小蓝","小橘","小绿",]
    response = agent.run(f"将使用pinyin拼音库这些客户名字转换为拼音，并打印输出列表: {customer_list}。")
    print(response)

    import langchain
    langchain.debug = True
    agent.run(f"使用pinyin拼音库将这些客户名字转换为拼音，并打印输出列表: {customer_list}")
    langchain.debug = False

